<template>
    <div class="app-container">
        <el-row>
            <el-button type="success" round @click="getList(1)">按天统计</el-button>
            <el-button type="primary" round @click="getList(2)">按周统计</el-button>
            <el-button type="danger" round @click="getList(3)">按月统计</el-button>
        </el-row>
        <el-table v-loading="listLoading" ref="dataList" :data="menuList" style="margin-bottom: 20px;" row-key="id" border :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column prop="time" label="日期" > </el-table-column>
            <el-table-column prop="user_code" label="房主编号" > </el-table-column>
            <el-table-column prop="room_code" label="房间编号" > </el-table-column>
            <el-table-column prop="room_name" label="房间名称" > </el-table-column>
            <el-table-column prop="order_num" label="订单总量" > </el-table-column>
            <el-table-column prop="demand_num" label="派单次数" > </el-table-column>
            <el-table-column prop="receive_num" label="有效派单次数" > </el-table-column>
            <el-table-column prop="avg_time" label="平均派单时长" > </el-table-column>
            <el-table-column label="操作" >
                <template slot-scope="scope">
                    <el-button
                    @click.native.prevent="jumpDetail(scope.row)"
                    type="text"
                    size="small">
                    查看详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <cus-pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.perPage" @pagination="getList"/>
    </div>
</template>

<script>
import {
  listData,
} from "@/api/sendOrders/sendOrdersData";
export default {
    data(){
        return {
            listLoading:true,
            menuList:[],
            total:0,
            listQuery: {
                pageNum: 1,
                perPage: 10,
                type:'',
            },
        }
    },
    created(){
        this.getList(1)
    },
    methods: {
        /* // 获取当前的时间
        getDate(data){
            let date = new Date(data);
            let Y = date.getFullYear() + "-";
            let M =
                (date.getMonth() + 1 < 10
                ? "0" + (date.getMonth() + 1)
                : date.getMonth() + 1) + "-";
            let D =
                (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
            let h =
                (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
            let m =
                (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
                ":";
            let s =
                date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            // Y + M + D + h + m + s)
            return Y + M + D + h + m + s;
        },
        // 获取今天零时的时间
        zeroTime(data){
            let date = new Date(data);
            let y = date.getFullYear();
            let m = date.getMonth()+1;
            let d = date.getDate();
            return y+'-'+this.add0(m)+'-'+this.add0(d)+' '+'00:00:00';
        },
        // 获取本周周一零时的时间
        monday() {
            let nowTemp = new Date(); //当前时间
            let oneDayLong = 24 * 60 * 60 * 1000; //一天的毫秒数
            let c_time = nowTemp.getTime(); //当前时间的毫秒时间
            let c_day = nowTemp.getDay() || 7; //当前时间的星期几
            let m_time = c_time - (c_day - 1) * oneDayLong; //当前周一的毫秒时间
            let monday = new Date(m_time); //设置周一时间对象
            let m_year = monday.getFullYear();
            let m_month = monday.getMonth() + 1;
            let m_date = monday.getDate();
            // m_year + "-" + m_month + "-" + m_date+ " 00:00:00"); //周一的年月日
            return m_year + "-" + m_month + "-" + m_date + " 00:00:00";
        },
        // 获取本月一号零时的时间
        oneday(data){
            let date = new Date(data);
            let y = date.getFullYear();
            let m = date.getMonth()+1;
            // y+'-'+this.add0(m)+'-01 00:00:00')
            return y+'-'+this.add0(m)+'-01 00:00:00';
        },
        // 自动补零函数
        add0(m){
            return m<10?'0'+m:m
        }, */

        getList(type){
            this.listLoading = true;
            this.listQuery.type = type
            let urlData = '?'
            if (this.listQuery.pageNum) {
                urlData = urlData + `page=${this.listQuery.pageNum}&`;
            }
            if (this.listQuery.perPage) {
                urlData = urlData + `perPage=${this.listQuery.perPage}`;
            }
            urlData += `&type=${type}`;
            // urlData)
            listData(urlData).then(response => {
                // response)
                this.menuList = response.data.list;
                this.total = response.data.meta.total;
                this.listLoading = false;
            })
        },
        jumpDetail(row){
            // row)
            this.$router.push({
                path: '/sendOrders/sendOrdersRoomData',
                query: {
                    type:this.listQuery.type,
                    room_id:row.room_id,
                    time:row.time_num
                }
            })
        },
    }
}
</script>

<style scoped>
    .el-row {
        margin-bottom: 20px;
    }
</style>
